package edu.fanhuiling.blogsystem.model;

import edu.fanhuiling.blogsystem.common.Constants;
import lombok.Data;

//接口统一返回结果   成功方法与失败方法
@Data
public class Result<T> {
    private Integer code;//200-成功 -1-失败   定义在Consatnts中了
    private String errMsg;
    private T data;

    public static <T>Result<T> success(T data){
        Result result=new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T>Result<T> fail(String errorMsg){
        Result result=new Result();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errorMsg);
        result.setData(null);
        return  result;
    }

    public static <T>Result<T> fail(String errorMsg,T data){
        Result result=new Result();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errorMsg);
        result.setData(data);
        return  result;
    }
}
